<%@ Page Language="C#" Inherits="IBuyAdventure.PageBase" src="components/stdpage.cs" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Register TagPrefix="IBA" TagName="Header" Src="UserControl\Header.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Categories" Src="UserControl\Categories.ascx" %>

<HTML>
  <HEAD>
    <TITLE>IBuyAdventure Catalog</TITLE>
  </HEAD>
 
  <script language="C#" runat="server">


      void Page_Load(Object sender, EventArgs e) {
      
         // Store Return Url in Page State 
         
         if (Request.QueryString["ReturnUrl"] != null) {
           ReturnUrl.Value = Request.QueryString["ReturnUrl"];
         }
      }

      void RegisterBtn_Click(Object sender, EventArgs e) {
 
        IBuyAdventure.UsersDB users = new IBuyAdventure.UsersDB(getConnStr());    
        IBuyAdventure.CartDB cart = new IBuyAdventure.CartDB(getConnStr());  
        
		if (users.UserExists(emailAddr.Text)) {
		  emailAddr.Text = "";
          Message.Text = "User Already Exists!!";
          return;
        }		
		
        if (Password.Text != ConfirmPassword.Text) {
          Message.Text = "Password Mismatch!!";
          return;
        }

        // Create new user account        

        users.AddNewUser(emailAddr.Text, Password.Text);
        
        // Set Client Authentication Cookie
        FormsAuthentication.SetAuthCookie(emailAddr.Text, (Persist.Checked == true));         

        // Migrate any temporary shopping cart items to logged-in username
        cart.MigrateShoppingCartItems(Session.SessionID, emailAddr.Text);        

        // Redirect user back to where they came from

        Response.Redirect(ReturnUrl.Value);



      }

  </script>

  <BODY BACKGROUND="images/back_sub.gif"> 

    <form method=post action="Register.aspx" runat="server">

      <FONT FACE="Verdana, Arial, Helvetica" SIZE=2>

        <TABLE BORDER=0>

          <tr>
            <td colspan=5>      
              <IBA:Header id="Header" runat="server"/>
            </td>
          </tr>  

          <!--Begin Navigational Buttons-->

          <TR>
            <TD ROWSPAN=5 ALIGN=LEFT VALIGN=TOP> 

              <IBA:Categories id="Categories" runat="server"/>
              
             
            </TD>
            <TD valign=top>

              <center>
              <br>

              <input type=hidden value="default.aspx" id="ReturnUrl" runat="server">
              <P><font size=2>Please enter your details below:<BR><BR>                                             
              <TABLE CELLPADDING=5 COLSPAN=2>
                <TR>
                  <TD WIDTH=310 BGCOLOR="#800000">
                    <FONT COLOR="#FFFFFF" STYLE="Verdana, Arial, Helvetica" SIZE=2><b>Register</b></FONT>
                  </TD>
                </TR>
                <TR>
                  <TD BGCOLOR="f7efde" VALIGN=TOP>
                    
                      <table>
                        <tr>
                          <td width=100><FONT SIZE=2>Email Address: </FONT></td>
                          <td><asp:textbox id="emailAddr" width=160 runat="server"/></td>
                        </tr>
                        <tr>
                          <td><FONT SIZE=2>Password: </FONT></td>
                          <td><asp:textbox id="Password" TextMode="Password" width=160 runat="server"/></td>
                        </tr>
                        <tr>
                          <td><FONT SIZE=2>Confirm Password: </FONT></td>
                          <td><asp:textbox id="ConfirmPassword" TextMode="Password" width=160 runat="server"/></td>
                        </tr>                        
                        <tr>
                          <td></td>
                          <td><asp:checkbox id="Persist" runat="server"/> <FONT SIZE=2>Remember Password</font></td>
                        </tr>                        
                        <tr>
                          <td colspan=2 align=right>
                            <asp:button Text="Register" OnClick="RegisterBtn_Click" runat="server"/>
                          </td>
                        </tr>
                      </table>
                      
                    </FONT>
                  </TD>
                </TR>
              </TABLE>
                                 
              <br><br>
              
              <font size=5 color=red>     
                <b>
                  <asp:label id="Message" runat="server"/>
                </b>
              </font>              
              
              </center>
              
            </TD>
          </TR>
        </TABLE>
      </FONT>
    </form>
  </BODY>
</HTML>

     